package org.hales.service;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.file.FileNameUtil;
import cn.hutool.poi.excel.ExcelWriter;
import org.hales.pojo.QuickFileVO;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 陈建康
 */

@Service
public class DownLoadService {
    public void collectEnvironmentFileNames(){
        String huanPingPath ="D:/tomcat/1300/webapps/EErDuoSi-Attach/17环评/环评";
        String paiWuXuKePath = "";
        List<QuickFileVO> huanPingFileList = new ArrayList<>();
        List<File> fileList = FileUtil.loopFiles(huanPingPath);
        for (File file : fileList) {
            String absolutePath  = file.getAbsolutePath().replace("\\", "/");;
            String relativePath =  absolutePath.substring(huanPingPath.length()).replace("\\", "/");
            String companyName = FileNameUtil.getPrefix(file.getParent());
            String fileName = FileNameUtil.getName(file);
            QuickFileVO quickFileVO = new QuickFileVO(companyName,fileName,absolutePath,relativePath);
            huanPingFileList.add(quickFileVO);
        }
        ExcelWriter excelWriter = new ExcelWriter("C:\\Users\\Administrator\\Desktop\\环评文件附件信息.xlsx");
        excelWriter.write(huanPingFileList,true);
        excelWriter.close();
    }
    public void collectPollutantFileNames(){
        String pollutantPath ="D:\\tomcat\\1300\\webapps\\EErDuoSi-Attach\\10排污许可正副本";
        List<QuickFileVO> huanPingFileList = new ArrayList<>();
        List<File> fileList = FileUtil.loopFiles(pollutantPath);
        for (File file : fileList) {
            String absolutePath  = file.getAbsolutePath().replace("\\", "/");;
            String relativePath =  absolutePath.substring(pollutantPath.length()).replace("\\", "/");
            String companyName = FileNameUtil.getPrefix(file.getParent());
            String fileName = FileNameUtil.getName(file);
            QuickFileVO quickFileVO = new QuickFileVO(companyName,fileName,absolutePath,relativePath);
            if(relativePath.contains("排污许可1.rar") || relativePath.contains("排污许可2.rar") || relativePath.contains("排污许可3.rar"))
                continue;
            huanPingFileList.add(quickFileVO);
        }
        ExcelWriter excelWriter = new ExcelWriter("C:\\Users\\Administrator\\Desktop\\排污许可副本附件信息.xlsx");
        excelWriter.write(huanPingFileList,true);
        excelWriter.close();
    }


}
